from rest_framework import serializers
from .models import Review
from user_app.serializers import UserSerializer, UserProfileSerializer
from vehicle_app.serializers import VehicleSerializer


class ReviewSerializer(serializers.ModelSerializer):
    """审核序列化器"""
    
    user = UserSerializer(read_only=True)
    vehicle = VehicleSerializer(read_only=True)
    user_profile = UserProfileSerializer(source='user.profile', read_only=True)
    
    class Meta:
        model = Review
        fields = [
            'id', 'type', 'status', 'user', 'vehicle',
            'reviewer', 'reason',
            'submitted_at', 'reviewed_at',
            'user_profile'
        ]
        read_only_fields = ['id', 'submitted_at', 'reviewed_at']


class ReviewCreateSerializer(serializers.ModelSerializer):
    """审核创建序列化器"""
    
    class Meta:
        model = Review
        fields = [
            'id', 'type', 'status', 'user', 'vehicle',
            'reviewer', 'reason',
            'submitted_at', 'reviewed_at'
        ]
        read_only_fields = ['id', 'submitted_at', 'reviewed_at']


class ReviewUpdateSerializer(serializers.ModelSerializer):
    """审核更新序列化器"""
    
    class Meta:
        model = Review
        fields = [
            'status', 'reviewer', 'reason', 'reviewed_at'
        ]